package com.mdd.front.service.product.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdd.front.service.product.IProductPropertyValueFrontService;
import com.mdd.front.vo.property.ProductPropertyValueDetailVo;
import com.mdd.product.entity.ProductPropertyValue;
import com.mdd.product.mapper.ProductPropertyValueMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 商品属性值实现类
 * @author LikeAdmin
 */
@Service
public class ProductPropertyValueFrontServiceImpl implements IProductPropertyValueFrontService {

    @Resource
    ProductPropertyValueMapper productPropertyValueMapper;

    /**
     * 商品属性值列表
     *
     * @author LikeAdmin
     * @param propertyId 属性id
     * @return PageResult<OmsProductPropertyValueListedVo>
     */
    @Override
    public List<ProductPropertyValueDetailVo> list(Long propertyId) {
        LambdaQueryWrapper<ProductPropertyValue> propertyWrapper = new LambdaQueryWrapper<>();
        propertyWrapper.eq(ProductPropertyValue::getPropertyId,propertyId);
        List<ProductPropertyValue> data = productPropertyValueMapper.selectList(propertyWrapper);

        List<ProductPropertyValueDetailVo> list = new LinkedList<>();
        for(ProductPropertyValue item : data) {
            ProductPropertyValueDetailVo vo = new ProductPropertyValueDetailVo();
            BeanUtils.copyProperties(item, vo);
            list.add(vo);
        }

        return list;
    }
}
